package com.codedancer.campus.manager.handler.impl.commodity;

import static com.codedancer.campus.enums.SystemMessageType.COMMODITY_OFF;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.common.utils.UUIDGenerator;
import com.codedancer.campus.enums.SystemMessageType;
import com.codedancer.campus.manager.handler.SystemMessageHandler;
import com.codedancer.campus.manager.service.model.SystemMessageMqParamModel;
import com.codedancer.campus.mapper.SystemMessageMapper;
import com.codedancer.campus.po.SystemMessage;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Data
@Component
@Slf4j
public class CommodityDropSystemMessageHandler implements SystemMessageHandler {

    @Autowired
    private SystemMessageMapper systemMessageMapper;

    private final SystemMessageType messageType = COMMODITY_OFF;

    @Override
    public void saveSystemMessage(SystemMessageMqParamModel systemMessageMqParamModel) {
        log.info("收到商品下架系统消息，{}", systemMessageMqParamModel);
        SystemMessage systemMessage = BeanUtil.copyProperties(systemMessageMqParamModel,
            SystemMessage.class);
        systemMessage.setUuid(UUIDGenerator.getUUID());
        systemMessageMapper.insert(systemMessage);
    }

    @Override
    public SystemMessageType getSystemMessageType() {
        return messageType;
    }
}
